package io.lkt.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;
import io.lkt.modules.sys.dao.BUserVipValidDao;
import io.lkt.modules.sys.entity.BUserVipValidEntity;
import io.lkt.modules.sys.service.BUserVipValidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("bUserVipValidService")
public class BUserVipValidServiceImpl extends ServiceImpl<BUserVipValidDao, BUserVipValidEntity> implements BUserVipValidService {

    @Autowired
    private BUserVipValidDao bUserVipValidDao;

    // gt-大于 ge-大于等于 lt-小于 le-小于等于
    // 大于30天
    @Override
    public PageUtils queryPageGe(Map<String, Object> params) {
        //获取当前日期
        LocalDate date = LocalDate.now();
        date = date.plusDays(30);

        IPage<BUserVipValidEntity> page = this.page(
                new Query<BUserVipValidEntity>().getPage(params),
                new QueryWrapper<BUserVipValidEntity>()
                        .ge("end_time", new Date())
                        .le("end_time", date)
                        .orderByAsc("end_time")
        );
        return new PageUtils(page);
    }

    // gt-大于 ge-大于等于 lt-小于 le-小于等于
    // 小于30天
    @Override
    public PageUtils queryPageLe(Map<String, Object> params) {
        //获取当前日期
        LocalDate date = LocalDate.now();
        date = date.plusDays(-30);

        IPage<BUserVipValidEntity> page = this.page(
                new Query<BUserVipValidEntity>().getPage(params),
                new QueryWrapper<BUserVipValidEntity>()
                        .le("end_time", new Date())
                        .ge("end_time", date)
                        .orderByDesc("end_time")
        );
        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //获取当前日期
        LocalDate date1 = LocalDate.now();
        date1 = date1.plusDays(30);

        LocalDate date2 = LocalDate.now();
        date2 = date2.plusDays(-30);

        IPage<BUserVipValidEntity> page = this.page(
                new Query<BUserVipValidEntity>().getPage(params),
                new QueryWrapper<BUserVipValidEntity>()
                        .le("end_time", date1)
                        .ge("end_time", date2)
                        .orderByDesc("end_time")
        );
        return new PageUtils(page);
    }

    @Override
    public List<BUserVipValidEntity> queryList(Map<String, Object> map){
        return this.bUserVipValidDao.queryList(map);
    }

    @Override
    public Integer queryTotal(Map<String, Object> map){
        return this.bUserVipValidDao.queryTotal(map);
    }

    @Override
    public String queryBrandName(Integer userId){
        return this.bUserVipValidDao.queryBrandName(userId);
    }

    @Override
    public Integer closeVipEndTime(Integer userId){
        return this.bUserVipValidDao.closeVipEndTime(userId);
    }

}
